package com.example.experiment2.controller;
import com.example.experiment2.entity.Grade;
import com.example.experiment2.service.GradeService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/grades")
public class GradeController {
    private   GradeService gradeService;
    public GradeController(GradeService gradeService) {
        this.gradeService = gradeService;
    }
    @GetMapping("/listAll")
    public List<Grade> listAll() {
        return gradeService.listAll();
    }

    @GetMapping("/getByCourseId/{courseId}")
    public List<Grade> getByCourseId(@PathVariable int courseId) {
        return gradeService.getByCourseId(courseId);
    }

    // 新增：获取成绩在指定范围内的学生成绩
    @GetMapping("/getByRange/{minScore}/{maxScore}")
    public List<Grade> getByRange(@PathVariable int minScore, @PathVariable int maxScore) {
        return gradeService.getByScoreRange(minScore, maxScore);
    }

    @PutMapping("/update")
    public String updategrade(@RequestBody Grade grade) {
        gradeService.updategrade(grade);
        return "更新成功";
    }
}